﻿<cfscript>
/** 
* ORM QuestionQuota
* 
* @hint "Hibernate persistenter t_quota. 问卷的内置指标" 
* 
*/ 

component 
	displayname="public.service.orm.senate.QuestionQuota" 
	output=false 
	persistent=true 
	selectBeforeUpdate=true dynamicInsert=true dynamicUpdate=true 
	cacheuse="Transactional" 
	entityname="QuestionQuota" 
	table="t_quota"
	{
	
	property type="string" name="QuotaID" column="quo_id" fieldtype="id" generator="assigned" hint="题目编号";

	property type="numeric" name="Idx" column="quo_idx" hint="指标显示排序";
	property type="string" name="Question" column="question" hint="指标描述";
	property type="string" name="Measure" column="measure" hint="评判模式";
	
	property name="Questionnaire" fieldtype="many-to-one" fkcolumn="qsn_id" cfc="Questionnaire"  hint="调查问卷";

	property name="QuestionVotes" type="array" lazy="true" inverse="true" cascade="delete-orphan" fieldtype="one-to-many" fkcolumn="quo_id" cfc="QuestionVote" hint="答题情况";	
	
	/**
	* @hint "自定义主键规则"
	* 
	* @Questionnaire "调查问卷"
	*/
	public string function getNextID( required Questionnaire ) output=false {
		
		var nextID = arguments.Questionnaire.getQueID() & numberFormat(1, "0__");
		
		var checkArray = ORMExecuteQuery("select QuotaID from QuestionQuota 
											where QuotaID like :condition 
											order by QuotaID desc", { condition = arguments.Questionnaire.getQueID() & "___" }, { maxResults=1 });
		
		/* 
			主键生成规则 
			
			8位问卷编号 + 3位流水号
			
		*/
		if (arrayLen(checkArray)) {
			/* 创建一个追加id */
			nextID = arguments.Questionnaire.getQueID() & numberFormat((right(checkArray[1], 3) + 1), "0__");
			
		}

		return nextID;
		
	}
	
}


</cfscript>